package com.example.projectcode.controller.Student;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.projectcode.model.Chapter;
import com.example.projectcode.model.College;
import com.example.projectcode.model.Subject;
import com.example.projectcode.model.Testpoint;
import com.example.projectcode.result.Result;
import com.example.projectcode.service.ChapterService;
import com.example.projectcode.service.CollegeService;
import com.example.projectcode.service.SubjectService;
import com.example.projectcode.service.TestPointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.beans.PropertyEditorSupport;
import java.util.*;

@Api(tags = "统考信息查看接口")
@RestController
@RequestMapping(value = "/user/viewUnifiedExamInfo")
public class ViewUnifiedExamInfoController {


    @Autowired
    private CollegeService collegeService;

    @Autowired
    private ChapterService chapterService;

    @Autowired
    private SubjectService subjectService;

    @Autowired
    private TestPointService testPointService;

    @ApiOperation("广东省院校信息查看")
    @GetMapping("/getCollegeInfo")
    public Result getCollegeInfo(){
        List<College> colleges = new ArrayList<>();
        colleges = collegeService.selectAllColleges();
        return Result.ok(colleges);
    }

    @ApiOperation("统考科目和考试大纲信息查看")
    @GetMapping("/getDetailInfo")
    public Result getDetailInfo(){

        Map<String, List<Chapter>> chapterMap = new HashMap<>();
        Map<String,List<Testpoint>> testpointMap = new HashMap<>();

        List<Subject> subjectList = new ArrayList<>();
        List<Chapter> chapterList = new ArrayList<>();
        List<Testpoint> testpointList = new ArrayList<>();

        subjectList = subjectService.selectAllSubject();

        for (Subject subject : subjectList){

            chapterList = chapterService.selectAllChapterBySubid(subject.getSubid());
            chapterMap.put(subject.getSubname(),chapterList);

            for (Chapter chapter : chapterList){
                testpointList = testPointService.selectAllTestPointByChapid(chapter.getChapid());
                testpointMap.put(chapter.getChapname(),testpointList);
            }
        }

        Map<String, Object> map = new HashMap<>();
        map.put("科目列表",subjectList);
        map.put("各科目对应的章节列表",chapterMap);
        map.put("各章节对应的考点列表",testpointMap);
        return Result.ok(map);



    }

/*-----------------------------------新加-----------------------------------*/
    @ApiOperation("分页查询所有学校")
    @GetMapping(value = "/queryAllCollege/{page}/{size}")
    public Result queryAllCollege(@PathVariable long page, @PathVariable long size){

        Page<College> collegePage = new Page<>(page,size);
        IPage<College> collegeIPage = collegeService.page(collegePage,null);

        return Result.ok(collegeIPage);
    }

    @ApiOperation("分页查询所有科目")
    @GetMapping(value = "/queryAllSubject/{page}/{size}")
    public Result queryAllSubject(@PathVariable long page, @PathVariable long size){

       Page<Subject> subjectPage = new Page<>(page,size);

       IPage<Subject> subjectIPage = subjectService.page(subjectPage,null);

      return Result.ok(subjectIPage);
    }

    @ApiOperation("分页查询所有章节")
    @GetMapping("/queryAllChapter/{page}/{size}")
    public Result queryAllChapter(@PathVariable long page, @PathVariable long size){

        Page<Chapter> chapterPage = new Page<>(page,size);
        IPage<Chapter> chapterIPage = chapterService.page(chapterPage,null);

        return Result.ok(chapterIPage);
    }


    @ApiOperation("分页查询所有考点")
    @GetMapping("/queryAllTestpoint/{page}/{size}")
    public Result queryAllTestpoint(@PathVariable long page, @PathVariable long size){
        Page<Testpoint> testpointPage = new Page<>(page,size);
        IPage<Testpoint> testpointIPage = testPointService.page(testpointPage,null);

        return Result.ok(testpointIPage);
    }







}
